//
//  TKIMSMSChatViewController.m
//  test2
//
//  Created by TryHone on 16/7/18.
//  Copyright © 2016年 TryHone. All rights reserved.
//

#import "TKIMSMSChatViewController.h"
#import "TKIMChatView.h"
#import "TKIMEmotionView.h"
#import "TKIMHttpRequestHelper.h"
#import "TKIMLayerUtils.h"
#import "TKIMLocationViewController.h"
//#import "TKIMOfficalDetailViewController.h"
#import "EBMWebViewViewController.h"
#import "TKIMRequestService.h"
#import "TKIMSMSChatView.h"

@interface TKIMSMSChatViewController () <TKIMMessageDelegate,
                                         TKIMManagerDelegate>
@property(nonatomic, strong) TKIMSMSChatView *chatView;
@property(nonatomic, strong) NSMutableArray *menusArray;

@property(nonatomic, strong) NSMutableArray *msgArray;

@end

@implementation TKIMSMSChatViewController

#pragma mark 系统方法

- (void)loadView {
  [super loadView];
  self.view.backgroundColor = [UIColor whiteColor];
  UIBarButtonItem *temBarButtonItem = [[UIBarButtonItem alloc] init];
  temBarButtonItem.title = @"";
  self.navigationItem.backBarButtonItem = temBarButtonItem;

  _msgArray = [[NSMutableArray alloc] init];
  //查询历史用户
  TKIMUser *hisUser =
      [[TKIMManager shareInstance] queryAHisUserByUserId:_user.userID];
  if (hisUser) {
    _user = hisUser;
  } else {
    NSString *username =
        [[TKIMDBManager shareInstance] queryTargetNameById:_user.userID];
    if (username && username.length) {
      _user.userName = username;
      _user.nickName = username;
    }
  }
    
    NSString *notiMaxDay = [TKIMSDKConfig shareInstance].tkNotiMaxDay;
    NSInteger *maxDay = [notiMaxDay integerValue];
    
    [[TKIMManager shareInstance]asyncDeleteUserHisMessageByUserId:_user.userID maxDay:maxDay];
    
  self.navigationItem.title = [TKIMHelper getShowNameWithUser:_user];
    CGRect rectOfStatusbar = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectOfNavigationbar = self.navigationController.navigationBar.frame;
  //聊天界面
  _chatView = [[TKIMSMSChatView alloc]
      initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
                               self.view.frame.size.height -rectOfStatusbar.size.height-rectOfNavigationbar.size.height)
               type:3];
  _chatView.delegate = self;
  [self.view addSubview:_chatView];

  //查询当前用户的历史消息
  __weak __typeof(self) weakSelf = self;
  [[TKIMManager shareInstance]
      asyncQueryUserHisMessageByUserId:_user.userID
                              callBack:^(NSMutableArray *array) {

                                if (weakSelf.msgArray) {
                                  [weakSelf.msgArray removeAllObjects];
                                }
                                [weakSelf.msgArray
                                    insertObjects:array
                                        atIndexes:[[NSIndexSet alloc]
                                                      initWithIndexesInRange:
                                                          NSMakeRange(
                                                              0, array.count)]];
                                [weakSelf.chatView
                                    reloadList:weakSelf.msgArray
                                    isNeedTime:!self.user.isNeedMangerBtn];
                              }];
    [self setBackBtn];
}


-(void)setBackBtn
{
    UIButton* back=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90, 44)];
    [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [back setImage:TKIMGetImage(@"btn_back") forState:UIControlStateNormal];
    back.tintColor=[UIColor whiteColor];
    back.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem=leftBar;
}

//返回按钮被点击
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dochoice:(id)btn {
  //做点其他的事
  __weak __typeof(self) weakSelf = self;
  _chatView.isSeletedState = !_chatView.isSeletedState;
  [_chatView dochoice:^(NSInteger state) {
    [weakSelf doStateChange:state];
  }];
}

- (void)dochoiceAll:(id)btn {

  __weak __typeof(self) weakSelf = self;

  [_chatView dochoiceAll:^(NSInteger state) {

    if (state == 0) {
        
        
        /*

      weakSelf.navigationItem.rightBarButtonItem =
          [[UIBarButtonItem alloc] initWithTitle:@"全选"
                                           style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(dochoiceAll:)];
      weakSelf.navigationItem.leftBarButtonItem =
          [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                           style:UIBarButtonItemStylePlain
                                          target:weakSelf
                                          action:@selector(dochoice:)];
         */
        
        
        
        [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"全选" imageName:nil buttonClickBlock:^{
            
            [self dochoiceAll:nil];
            
        }];
        
        [self baseCreateViewInNavigationBarLeftButtonWtihTitle:@"取消" imageName:nil buttonClickBlock:^{
            
            
            [self dochoice:nil];
            
        }];
        
        

    } else {

        /*
      weakSelf.navigationItem.rightBarButtonItem =
          [[UIBarButtonItem alloc] initWithTitle:@"取消全选"
                                           style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(dochoiceAll:)];
      weakSelf.navigationItem.leftBarButtonItem =
          [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                           style:UIBarButtonItemStylePlain
                                          target:weakSelf
                                          action:@selector(dochoice:)];
         */
        
        
        [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"取消全选" imageName:nil buttonClickBlock:^{
            
            [self dochoiceAll:nil];
            
        }];
        
        [self baseCreateViewInNavigationBarLeftButtonWtihTitle:@"取消" imageName:nil buttonClickBlock:^{
            
            
            [self dochoice:nil];
            
        }];
        
    }

  }];
}

- (void)doStateChange:(NSInteger)state {
    
    if (state) {
        
        /*
        self.navigationItem.leftBarButtonItem = nil;
        UIBarButtonItem *temBarButtonItem = [[UIBarButtonItem alloc] init];
        temBarButtonItem.title = @"";
        self.navigationItem.backBarButtonItem = temBarButtonItem;
        _chatView.tableView.allowsSelection = NO;
        self.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:@"管理"
                                         style:UIBarButtonItemStylePlain
                                        target:self
                                        action:@selector(dochoice:)];
         */
        
        
         _chatView.tableView.allowsSelection = NO;
        
        [self baseCreateLeftBackButtonWithBackImage:@"Navigation_Back"];
        
        [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"管理" imageName:nil buttonClickBlock:^{
            
            [self dochoice:nil];
            
        }];
        
        
    } else {
        
        /*
        self.navigationItem.leftBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                         style:UIBarButtonItemStylePlain
                                        target:self
                                        action:@selector(dochoice:)];
        _chatView.tableView.allowsSelection = YES;
        self.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:@"全选"
                                         style:UIBarButtonItemStylePlain
                                        target:self
                                        action:@selector(dochoiceAll:)];
         */
        
        
        _chatView.tableView.allowsSelection = YES;
        
        [self baseCreateViewInNavigationBarLeftButtonWtihTitle:@"取消" imageName:nil buttonClickBlock:^{
            
            [self dochoice:nil];
            
        }];
        
        [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"全选" imageName:nil buttonClickBlock:^{
            
            [self dochoiceAll:nil];
            
        }];
        
        
    }
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [[TKIMManager shareInstance] resetUserConverseCount:_user.userID];
  if (_chatView.tableView.isEditing) {
      
      /*
      
    self.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                         style:UIBarButtonItemStylePlain
                                        target:self
                                        action:@selector(dochoice:)]; //管理按钮
       */
      
      [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"取消" imageName:nil buttonClickBlock:^{
          
          [self dochoice:nil];
          
      }];
      
      
  } else {
      
      /*
    self.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:@"管理"
                                         style:UIBarButtonItemStylePlain
                                        target:self
                                        action:@selector(dochoice:)]; //管理按钮
       */
      
      
      [self baseCreateViewInNavigationBarRightButtonWtihTitle:@"管理" imageName:nil buttonClickBlock:^{
          
          [self dochoice:nil];
          
      }];
  }

  //假如需要上传消息的已读状态
  if (self.isNeedSetState) {
    [TKIMSDKManager setMsgState:nil
                        msgType:self.user.userID
                       callback:^(NSInteger errorNumber, NSString *info) {
                         if (errorNumber == 0) {
                           self.isNeedSetState = false;
                         }
                       }];
  }
}

- (void)viewDidLoad {
  [super viewDidLoad];
  //请求公众号菜单
  [self loadOfficailMenu];
  //修改昵称的通知
  [[NSNotificationCenter defaultCenter]
      addObserver:self
         selector:@selector(modifyNickname)
             name:TKIMModifyNicknameNotification
           object:nil];
  //#warning 防止重复监听
  [[TKIMManager shareInstance] unRegisterDelegate:self];
  //#warning 注册代理监听
  [[TKIMManager shareInstance] registerDelegate:self];
}

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  //清除用户的会话数
  [[TKIMManager shareInstance] resetUserConverseCount:_user.userID];

  NSInteger total = [[TKIMDBManager shareInstance] queryConverseTotal];
  [[TKIMManager shareInstance]
      syncUserMsgCountToServer:total
                      callBack:^(TKIMResultVo *resultVo){
                      }];

  UIApplication *app = [UIApplication sharedApplication];
  app.applicationIconBadgeNumber = total;
}

#pragma mark 方法
/**
 *  @Author lpm, 15-07-28 10:07:57
 *
 *  @brief  发送消息
 *
 *  @param msg 消息
 */
- (void)sendMessage:(TKIMMessage *)msg {
  msg.toUser = _user.userID;
  msg.toJid = _user.jid;
  msg.chatUserType = _user.userType;
  [[TKIMManager shareInstance] sendMessage:msg];
}

/**
 *  @Author zrs, 15-12-11 09:12:11
 *
 *  @brief  查询历史消息委托
 *
 *  @param messageCount 消息数
 *  @param historyDataBlock 回调
 */
- (void)requestMoreHistoryMessagecount:(NSInteger)messageCount
                      historyDataBlock:
                          (void (^)(NSMutableArray *))historyDataBlock {
  //    [[TKIMManager shareInstance]
  //    asyncQueryUserHisMessageByUserId:self.user.userID count:messageCount
  //    callBack:^(NSMutableArray *array){
  //        historyDataBlock(array);
  //    }];

  TKIMWS(weakself);
  TKIMMessage *msg = self.msgArray.firstObject;
  NSInteger startIndex = 1;
  if (msg) {
    startIndex = msg.refId.integerValue;
  }
  [[TKIMManager shareInstance]
      loadUserHisMsgFromServer:self.user.userID
                    startIndex:startIndex
                         count:
                  messageCount:^(TKIMResultVo *resultVo) {
                    if (resultVo.errorNo == 0) {
                      NSMutableArray *array =
                          (NSMutableArray *)resultVo.results;
                      NSIndexSet *indexes = [NSIndexSet
                          indexSetWithIndexesInRange:NSMakeRange(
                                                         0, [array count])];
                      [weakself.msgArray insertObjects:array atIndexes:indexes];
                    }
                    historyDataBlock([weakself.msgArray mutableCopy]);
                  }];
}

/**
 *  @Author lpm, 16-05-10 09:05:46
 *
 *  @brief  请求公众号菜单
 */
- (void)loadOfficailMenu {
  //请求公众号的菜单数据
  if (_user.userType == TKIMUserTypeOfficial) {
    TKIMRequestService *service = [[TKIMRequestService alloc] init];
    [service getOfficialMenusWithUsername:_user.userID
                                 callBack:^(TKIMResultVo *resultVo) {
                                   if (resultVo.errorNo == 0) {
                                     self.chatView.menusArray =
                                         (NSArray *)resultVo.results;
                                   } else {
                                     [[TKIMLayerUtils instance]
                                         showTip:resultVo.errorInfo];
                                   }
                                 }];
  }
}

/**
 *  @author zhengrs, 16-04-29 11:04:35
 *
 *  @brief 修改昵称成功后重新刷新界面
 */
- (void)modifyNickname {
  self.navigationItem.title = [TKIMHelper getShowNameWithUser:self.user];
  [[TKIMManager shareInstance]
      asyncQueryUserHisMessageByUserId:_user.userID
                              callBack:^(NSMutableArray *array) {
                                [_chatView
                                    reloadList:array
                                    isNeedTime:!self.user.isNeedMangerBtn];
                              }];
}


#pragma mark 事件路由
/**
 *  @Author lpm, 15-12-02 13:12:11
 *
 *  @brief  事件路由
 *
 *  @param eventName
 *  @param userInfo
 */
- (void)routerEventWithName:(NSString *)eventName
                   userInfo:(NSObject *)userInfo {
  if ([eventName isEqualToString:TKIMSrvTemplOnclick]) {
    [self jumpToOfficailDetail:userInfo];
  } else if ([eventName isEqualToString:TKIMSubMenuClickEvent]) {
    [self officailMenuClickEvent:userInfo];
  } else if ([eventName isEqualToString:TKIMAudioChatSelectedEvent]) {
    [self jumpToVoiceChat:userInfo];
  } else if ([eventName isEqualToString:TKIMVideoChatSelectedEvent]) {
    [self jumpToVideoChat:userInfo];
  } else if ([eventName isEqualToString:TKIMLocationClickEvent]) {
    [self jumpToMap:userInfo];
  } else if ([eventName isEqualToString:TKIMMsgHeadImageTapEvent]) {
//    [self msgHeadOnclick:userInfo];
  } else if ([eventName isEqualToString:TKIMScoreEvent]) {
    [self scoreEvent:userInfo];
  } else if ([eventName isEqualToString:TKIMToScoreEvent]) {
    NSLog(@"TKIMToScoreEvent===");
  } else if ([eventName isEqualToString:TKIMLinkOnClick]) {
    [self linkOnClick:userInfo];
  } else if ([eventName isEqualToString:@"Delete_Msg"]) {

    [self doStateChange:1];
  } else if ([eventName isEqualToString:TKIMMsgClickEvent]) { //消息被点击事件
    [self dealWithClickMsgSendClickState:(TKIMMessage *)userInfo];
  }
}

- (void)dealWithClickMsgSendClickState:(TKIMMessage *)msg {

  if (msg) {
    NSString *state = msg.ext[TKIMMsgClickEvent];
    NSString *serviceNo = msg.ext[@"serialNo"];

    if (![@"1" isEqualToString:state] && serviceNo &&
        serviceNo.length) { //已经发生过该消息

      [[TKHttpService sharedInstance]
          updateMsgClickState:serviceNo
                         ofid:[TKIMManager shareInstance].loginUser.userID
                     callback:^(TKIMResultVo *resultVo) {

                       if (resultVo.errorNo == 0) {
                         msg.ext[TKIMMsgClickEvent] = @"1";
                         [[TKIMDBManager shareInstance] updateMsgExt:msg];
                       }

                     }];
    }
  }
}

/**
 *  @Author lpm, 16-05-10 10:05:27
 *
 *  @brief  跳转到公众号详情
 *
 *  @param userInfo
 */
- (void)jumpToOfficailDetail:(NSObject *)userInfo {

  TKIMSrvRichItem *item = (TKIMSrvRichItem *)userInfo;
  switch (item.actiontype) {
  case SDKItemActionType_App: { //默认操作
    [self defaultAppAction:item];
  } break;
  case SDKItemActionType_Url: { //默认操作
    [self openUrl:item];
  } break;
  case SDKItemActionType_Activity: { //默认操作
    [self defaultAppAction:item];
  } break;
  case SDKItemActionType_Custom: { //由用户处理
    NSMutableDictionary *dict = nil;
    if (item.ext) {
      dict = [[NSMutableDictionary alloc] initWithDictionary:item.ext];
      if (item.url && item.url.length) {
        [dict setObject:item.url forKey:@"sdkurl"];
      }

    } else {

      dict = [[NSMutableDictionary alloc] init];
      if (item.url && item.url.length) {
        [dict setObject:item.url forKey:@"sdkurl"];
      }
    }

    [[NSNotificationCenter defaultCenter]
        postNotificationName:MESSAGE_ITEM_CLICK
                      object:nil
                    userInfo:dict]; //暂时性处理
  } break;

  default:
    [self defaultAppAction:item];
    break;
  }
}

- (void)defaultAppAction:(TKIMSrvRichItem *)item {

  if (item && item.url && item.url.length > 0) {
      /*
    TKIMOfficalDetailViewController *detail =
        [[TKIMOfficalDetailViewController alloc] init];
    detail.item = item;
    detail.isAutoTitle = NO;
    detail.navtitle = self.navigationItem.title;
    [self.navigationController pushViewController:detail animated:YES];
       */
      
      
      EBMWebViewViewController *webView = [[EBMWebViewViewController alloc]initWithUrlString:item.url titleString:self.navigationItem.title];
      [self.navigationController pushViewController:webView animated:YES];
  }
}

- (void)openUrl:(TKIMSrvRichItem *)item {
  NSString *url = item.actionValue;
  if (url && url.length > 0) {
      /*
    item.url = url;
    TKIMOfficalDetailViewController *detail =
        [[TKIMOfficalDetailViewController alloc] init];
    detail.item = item;
    detail.isAutoTitle = NO;
    detail.navtitle = self.navigationItem.title;
    [self.navigationController pushViewController:detail animated:YES];
       */
      
      
      EBMWebViewViewController *webView = [[EBMWebViewViewController alloc]initWithUrlString:item.url titleString:self.navigationItem.title];
      [self.navigationController pushViewController:webView animated:YES];
      
  } else { //走默认的情形
    [self defaultAppAction:item];
  }
}

/**
 *  @Author lpm, 16-05-10 10:05:36
 *
 *  @brief  公众号子菜单点击
 *
 *  @param userInfo
 */
- (void)officailMenuClickEvent:(NSObject *)userInfo {
    
    /*
  TKIMOfficalDetailViewController *detail =
      [[TKIMOfficalDetailViewController alloc] init];
  detail.menuItem = (TKIMMenuBarItem *)userInfo;
  [self.navigationController pushViewController:detail animated:YES];
     */
    
    
    TKIMMenuBarItem * menuItem = (TKIMMenuBarItem *)userInfo;
    
    EBMWebViewViewController *webView = [[EBMWebViewViewController alloc]initWithUrlString:menuItem.key titleString:menuItem.menu_name];
    [self.navigationController pushViewController:webView animated:YES];
    
    
}

/**
 *  @Author lpm, 16-05-10 10:05:27
 *
 *  @brief  语音聊天
 *
 *  @param userInfo
 */
- (void)jumpToVoiceChat:(NSObject *)userInfo {
  [[TKIMLayerUtils instance] showLoading:YES withLabel:@"连接中"];
  [[TKIMManager shareInstance] sendVoiceRequestTo:_user.userID];
}

/**
 *  @Author lpm, 16-05-10 10:05:33
 *
 *  @brief  视频聊天
 *
 *  @param userInfo
 */
- (void)jumpToVideoChat:(NSObject *)userInfo {
  [[TKIMLayerUtils instance] showLoading:YES withLabel:@"连接中"];
  [[TKIMManager shareInstance] sendVideoRequestTo:_user.userID];
}

/**
 *  @Author lpm, 16-05-10 10:05:17
 *
 *  @brief  跳转到地图
 *
 *  @param userInfo
 */
- (void)jumpToMap:(NSObject *)userInfo {
  TKIMLocationViewController *location =
      [[TKIMLocationViewController alloc] init];
  if (userInfo) {
    location.location = (TKIMLocationMessage *)userInfo;
  }
  location.delegate = _chatView;
  [self.navigationController pushViewController:location animated:YES];
}


/**
 *  @Author lpm, 16-05-10 10:05:43
 *
 *  @brief 打分
 *
 *  @param userInfo
 */
- (void)scoreEvent:(NSObject *)userInfo {
  [[TKIMLayerUtils instance] showLoading:YES];
  [[TKIMManager shareInstance]
      sendScoreRequest:_user.userID
              callBack:^(TKIMResultVo *resultVo) {
                [[TKIMLayerUtils instance] showLoading:NO];
                [[TKIMLayerUtils instance] showTip:resultVo.errorInfo];
                NSLog(@"%@", resultVo.errorInfo);
              }];
}

/**
 *  @Author lpm, 16-05-10 11:05:06
 *
 *  @brief  链接被点击
 *
 *  @param userInfo
 */
- (void)linkOnClick:(NSObject *)userInfo {
  //        [[UIApplication sharedApplication] openURL:[NSURL
  //        URLWithString:(NSString *)userInfo]];
    
    /*
  TKIMOfficalDetailViewController *detail =
      [[TKIMOfficalDetailViewController alloc] init];
  TKIMSrvRichItem *item = [[TKIMSrvRichItem alloc] init];
  item.url = (NSString *)userInfo;
  //    item.title = @"";
  detail.isAutoTitle = YES;
  detail.item = item;
  [self.navigationController pushViewController:detail animated:YES];
     */
    
    
    TKIMMenuBarItem * menuItem = (TKIMMenuBarItem *)userInfo;
    
    EBMWebViewViewController *webView = [[EBMWebViewViewController alloc]initWithUrlString:menuItem.key titleString:menuItem.menu_name];
    [self.navigationController pushViewController:webView animated:YES];
    
}

#pragma mark 监听代理（更多代理可在TKIMManagerDelegate中查看）

//#warning 特别注意以下为im代理监听，必须注册为监听代理才会被调用
/**
 *  @Author lpm, 15-09-16 13:09:17
 *
 *  @brief  收到消息
 *
 *  @param sender
 *  @param message
 */
- (void)didReceiveMessage:(TKIMMessage *)message {
  if (message) {
    if ([message.fromUser isEqualToString:_user.userID]) {
      if ((message.chatUserType != TKIMUserTypeGroup) &&
          (message.chatUserType != TKIMUserTypeRoom)) {
        [_chatView receiveMsg:message];
          [self.msgArray addObject:message];
      }
    }
  }
}

/**
 *  @Author lpm, 15-11-07 12:11:27
 *
 *  @brief  消息发送结果回调
 *
 *  @param message
 *  @param error
 */
- (void)didSendMessage:(TKIMMessage *)message error:(NSError *)error {
  [_chatView updateMsg:message];
}

/**
 *  @Author lpm, 15-12-09 15:12:59
 *
 *  @brief  收到消息被清空事件
 *
 *  @param error
 */
- (void)didReceiveMessageClean:(NSError *)error;
{
  [_chatView reloadList:[@[] mutableCopy]
             isNeedTime:!self.user.isNeedMangerBtn];
}

/**
 *  @Author lpm, 15-12-17 10:12:41
 *
 *  @brief  收到app被杀死或者退出登录的事件
 */
- (void)didReceiveAppInterruption {
  //清除用户的会话数
  [[TKIMManager shareInstance] resetUserConverseCount:_user.userID];
}

/**
 *  @Author lpm, 15-12-02 19:12:09
 *
 *  @brief
 *
 *  @param data
 *  @param error
 */
- (void)didReceiveVideoVoiceChatRequestResult:(TKIMVideoChat *)data
                                        error:(NSError *)error {
  [[TKIMLayerUtils instance] showLoading:NO];
  if (!error) {
    data.userName = _user.userID;
    [[NSNotificationCenter defaultCenter]
        postNotificationName:TKIMShowVideoVoiceNotification
                      object:data];
  } else {
    NSDictionary *userInfo = error.userInfo;
    NSString *tip = userInfo[@"errorInfo"];
    [[TKIMLayerUtils instance] showTip:tip];
  }
}

#pragma mark 属性
- (NSMutableArray *)menusArray {
  if (!_menusArray) {
    _menusArray = [NSMutableArray array];
  }
  return _menusArray;
}

- (void)dealloc {
  [_chatView removeCss];
  _chatView = nil;
  //#warning 解注代理监听
  [[TKIMManager shareInstance] unRegisterDelegate:self];
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
